className = get_class();// Set current class $this->zColumnList = array("dataId", "createDate","createdBy","OrgID","TeamID","RelatedUser","AmountIn","AmountOut","TransactionType","MonthlyPayIndex","Comments"); $this->zColumnType = array("VARCHAR(8)","VARCHAR(32)","VARCHAR(8)","VARCHAR(8)","VARCHAR(8)","VARCHAR(8)","DECIMAL","DECIMAL","VARCHAR(8)","DECIMAL","VARCHAR(64)"); //For search and reporting only $this->zReportCols = array("dataId", "createDate","createdBy","TeamID","RelatedUser","AmountIn","AmountOut","TransactionType","Comments");//zBlob should not be here $this->zReportColsHeader = array("ID","Date","Created By","Team","Related User","Deposite","Loan","Type","Comments");//zBlob should not be here if($OrgID!="" && $TransactionType!="" && ($AmountIn>0||$AmountOut>0)){ $this->OrgID=$OrgID; $this->TeamID=$TeamID; $this->RelatedUser=$RelatedUser; $this->AmountIn=$AmountIn; $this->AmountOut=$AmountOut; $this->TransactionType=$TransactionType; $this->Comments=$Comments; $totalDays = (float)date('t'); $todayIndex = (float)date('j'); if($totalDays>0 && $TransactionType=="DPO") $this->MonthlyPayIndex=round(($totalDays-$todayIndex)/$totalDays,2); $this->_save(); } } } class teams extends team{ public function __construct($OrgID="",$cBy="System",$uBy="System",$TeamName=""){ parent::__construct(cBy:$cBy,uBy:$uBy,tNam:$TeamName,oId:$OrgID,classN:'teams'); //$this->className = 'teams'; } } class users extends user{ public $userName; public $language; public function __construct(){ parent::__construct(classN:'users',idPre:"U-"); $this->className = 'users'; $this->zBrowseList = array("workId","userName","createDate","createdBy","updateDate","updatedBy","contact","email","userType","userGroup","canAccessApp","isActive","reportsTo","orgID");//zBlob should not be here $this->zColumnList = array("workId","userName","createDate","createdBy","updateDate","updatedBy","contact","email","userType","userGroup","canAccessApp","isActive","reportsTo","orgID","zBlob"); $this->zColumnType = array("VARCHAR(8)","VARCHAR(128)","VARCHAR(32)","VARCHAR(32)","VARCHAR(32)","VARCHAR(32)","VARCHAR(16)","VARCHAR(64)","VARCHAR(4)","VARCHAR(8)","BOOLEAN","BOOLEAN","VARCHAR(8)","VARCHAR(8)","LONGTEXT"); //For search and reporting only $this->zReportCols = array("workId","User Name","contact","email","userType","userGroup","canAccessApp","isActive");//zBlob should not be here $this->zReportColsHeader = array("ID","User Name","Contact","Email","User Type","Team","Can Access","Is Active");//zBlob should not be here } public function _login($uId="",$pwd="",$saveLocal=false){ $usr = new users(); $data = $usr->_getUserContext('userContextCo');//retrieve coOperative user context //echo json_encode($data);exit; if(_startsWith ($data->workId,"U-")) return $data->workId; if($uId=="") return "Error: Used ID empty!"; if($pwd=="") return "Error: Password empty!"; $lst = $this->_list(select:"workId",where:"(email='$uId' OR contact='$uId' OR workId='$uId') AND isActive is true"); if($lst->resultsCount<=0){ return 'Error: User not found'; }else{ $this->_openById($lst->results[0]->workId); if($pwd==$this->password){ if($saveLocal==true){ $this->_saveUserContext("userContextCo",100); } return $this->workId; } else return 'Error: Incorrect password!'; } return 'Error: Exception while executing the query.'; } } function _logout(){ setcookie("userContextCo", "", time() - 3600, "/"); } function hasRole($userID="",$requiredRole="USR") { $usr = new users(); $data = $usr->_getUserContext(); if($userID=="" || $data->workId==$userID){ return $data->role===$requiredRole; }else{ $tmpObj = $usr->_browse(select:"role",where:"workId='$userID'",isExecute:true); if($tmpObj->status==true){ return $tmpObj->results[0]->role===$requiredRole; } return false; } return false; } function isAdmin($userID=""){ return hasRole($userID,"ADM"); } function isUser($userID=""){ return hasRole($userID,"USR"); } function isManager($userID=""){ return hasRole($userID,"MGR"); } //Run first tiome to generate tables /* $o = new organization(); $o->_createTable(true); $org = new organization(oNam:"CoOperative"); $orgId = $org->dataId; echo "Organization Created ID#$orgId
"; */ //$t = new teams(); //echo json_encode($t); // $t->_createTable(true); // $tm = new teams(TeamName:"Default",OrgID:'ORG-3'); // $tmId= $tm->dataId; // echo "Team Created ID#$tmId
"; /* $ad = new address(); $ad->_createTable(true); $i = new item(); $i->_createTable(true); */ /* $tr = new transactions(); $tr->_createTable(true); echo "Table Created for Address & Transactions
";*/ /* $u = new users(); $u->_openById('U-6'); $u->userType = 'ADM'; $u->_save();*/ //$u->_createTable(true); //$flg= $u->_addNewUser(name:"Rajat",email:"rajat70@gmail.com",contact:"9748448117",teamId:$tmId,orgID:$orgId); // echo "User #$u->workId created
"; ?>